package com.flx.multi.thread.juc.locks.reentrant;

import java.util.concurrent.locks.ReentrantLock;

/**
 * @Author Fenglixiong
 * @Create 2021/11/15 20:01
 * @Description
 **/
public class ReentrantLockTest {

    public static void main(String[] args) {

        final ReentrantLock lock = new ReentrantLock(true);

        Thread t1 = new Thread(()->{
            try {
                lock.lock();
                System.out.println("线程一加锁成功...");
                System.out.println("线程一执行业务逻辑...");
            }finally {
                lock.unlock();
                System.out.println("线程一释放锁成功...");
            }
        });
        Thread t2 = new Thread(()->{
            try {
                lock.lock();
                System.out.println("线程二加锁成功...");
                System.out.println("线程二执行业务逻辑...");
            }finally {
                lock.unlock();
                System.out.println("线程二释放锁成功...");
            }
        });

        t1.start();
        t2.start();
    }

}
